using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.IO;


namespace DAH_TD
{
    public class Map : Microsoft.Xna.Framework.DrawableGameComponent
    {
        private SpriteBatch spriteBatch;
        SpriteFont font;

        private const int tile_breite = 50;
        private const int tile_hoehe = 50;

        private const int map_hoehe = 9;
        private const int map_breite = 16;

        public int[,] getTilemap()
        { return tilemap; }

        public void setTilemap(int x, int y, int value)
        { this.tilemap[x, y] = value; }

        private int[,] tilemap = new int[map_hoehe, map_breite]
        {
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 },
        { 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0 },
        { 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1 },
        { 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
        };

        private Texture2D[] map_textures = new Texture2D[2];
        
        public Map(Game game)
            : base(game)
        {
            spriteBatch = new SpriteBatch(game.GraphicsDevice);
        }
        
        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void LoadContent()
        {
            map_textures[0] = Game.Content.Load<Texture2D>("Graphics/Tile01");
            map_textures[1] = Game.Content.Load<Texture2D>("Graphics/Tile_path_01");
            font = Game.Content.Load<SpriteFont>("Font1");
        }


        protected override void UnloadContent()
        {
        }

        string output;
        string temp;
        string x;
        string y;

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            spriteBatch.Begin();


            // alle Zeilen durchlaufen
            for (int i = 0; i < map_hoehe; i++)
            {
                // alle Spalten durchlaufen
                for (int j = 0; j < map_breite; j++)
                {
                    x = i.ToString();
                    y = j.ToString();
                    temp = "\nTile: " + x + " , " + y + "\n" + tilemap[i, j] + "\n0"; 
                    output = output + temp;
                    /*
                    // Zeichnet "Grund" 
                    spriteBatch.Draw(map_textures[0], new Rectangle(tile_breite * j, tile_hoehe * i, tile_breite, tile_hoehe), Color.White);
                    // Zeichnet Objekt auf Grund - entsprechend der Zahl in der Matrix
                    spriteBatch.Draw(map_textures[tilemap[i, j]], new Rectangle(tile_breite * j, tile_hoehe * i, tile_breite, tile_hoehe), Color.White);
                    */
                }
            }
            Console.Write(output);
            //spriteBatch.DrawString(font, output, new Vector2(0, 0), Color.Red);
                       
            spriteBatch.End();
        }
    }
}
